<template>
  <div class="login">
     <div class="navbar-wrap">
      <div class="Navbarold">
        <nav>
          <div class="navbar-logo">
            <a class="navbar-back" href="javascript:history.back();"></a>
          </div>
          <div class="navbar-title">猫眼电影</div>
          <div class="navbar-button"></div>
        </nav>
      </div>
    </div>


    <div class="reg-content">
      <input type="text" placeholder="用户名" v-model="user"><br>
      <input type="password" placeholder="密码" v-model="password"><br>
      <button @click="login">登 录</button>
      <p class="register">没有账号？<span @click="$router.push('/register')">点我注册</span></p>
    </div>
  </div>
</template>

<script>
import { mapGetters, mapMutations } from "vuex";
export default {
  data() {
    return {
      user: '',
      password: ''
    }
  },
  computed: {
    ...mapGetters(['testUserInfo']),
  },
  methods: {
    ...mapMutations(['loginIn']),
    login() {
      if(!this.user.trim()) return alert('用户名不能为空！');
      if(!this.password) return alert('请输入密码！');
      let testInfo = this.testUserInfo(this.user)
      if (!testInfo) return alert('用户名不存在！');
      if (this.user === testInfo.account && this.password === testInfo.password) {
        this.loginIn(testInfo)
        this.$router.push('/me')
      } else {
        alert('密码错误！！')
        // 可选项：输入错误后清空用户名和密码
        // this.user = ''
        // this.password = ''
      }
    }
  }
}
</script>

<style lang="less" >
.login{

.Navbarold {
  height: 50px;
  background-color: #e54847 !important;
  display: -webkit-box;
  height: 38px;
  overflow: hidden;
  position: relative;
  padding: 6px;
  box-sizing: content-box;
  nav {
    width: 100%;
    display: -webkit-box;
    .navbar-logo {
      width: 100px;
      background-size: 37%;
      .navbar-back {
        width: 36px;
        height: 36px;
        display: block;
        z-index: 999;
      }
      .navbar-back:after {
        content: "";
        top: 16px;
        left: 12px;
        width: 13px;
        height: 13px;
        position: absolute;
        border: 2px solid #fff;
        border-width: 0 0 2px 2px;
        transform: rotate(45deg);
      }
    }

    .navbar-title {
      -webkit-box-flex: 1;
      color: #fff;
      font-size: 18px;
      text-align: center;
      line-height: 2;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      position: relative;
    }
    .navbar-button {
      position: relative;
      width: 100px;
      display: flex;
      align-items: center;
      justify-content: flex-end;
    }
  }
}
.reg-content {
  width: 300px;
  padding: 0 5%;
  input, button {
    width: 100%;
    border: none;
    outline: none;
    margin-top: 12px;
  }
   input {
    padding: 12px 23px;
    border-bottom: 1px solid #bfbfbf;
  }
   button {
    color: #fff;
    padding: 10px 0;
    margin-top: 22px;
    border-radius: 5px;
    background-color: #f03d37;
    margin-left: 17px;
  }
   .register {
    margin-top: 12px;
    font-size: 14px;
    color: #888;
     span {
      color: #f03d37;
    }
  }
}
}
</style>
